package com.zjbti.contentp;

import android.content.ClipData;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.zjbti.contentp.ContactInfo; // 请替换为实际的包名

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import java.util.List;

public class ContactAdapter extends RecyclerView.Adapter {
    private  List<ClipData.Item> contactInfos;
    private List<ContactInfo> contactList;

    public ContactAdapter(MainActivity mainActivity, List<ContactInfo> contactInfos) {
        this.contactList = contactInfos;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_layout,parent,false);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        // 获取当前条目的数据
        ContactInfo contactInfo = contactList.get(position);

        // 将数据绑定到 ViewHolder 的视图上
        ViewHolder viewHolder = (ViewHolder) holder; // 将 holder 转换为 ViewHolder
        viewHolder.tv_name.setText(contactInfo.getName()); // 设置姓名
        viewHolder.tv_number.setText(contactInfo.getNumber()); // 设置电话号码
    }
    @Override
    public int getItemCount() {
        return contactList.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        public TextView tv_name;
        public TextView tv_number;
        public ViewHolder(View itemView) {
            super(itemView);
            tv_name = itemView.findViewById(R.id.tv_name);
            tv_number = itemView.findViewById(R.id.tv_number);
        }
    }
}
